package com.example.booksales.controller;

import com.example.booksales.domain.Shop;
import com.example.booksales.service.impl.ShopService;
import com.example.booksales.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/shop")
@Api(tags="书店管理(0613胡宇星)")
public class ShopController {
    @Autowired
    private ShopService shopService;
    @ApiOperation("获得全部书店列表(22001010613胡宇星)")
    @GetMapping("/list")
    public AjaxResult list(){
        return AjaxResult.success(shopService.getAllShops());
    }
    @ApiOperation(value = "获取书店详细信息(22001010613胡宇星)", notes = "TODO：取得某个书店的详细信息")
    @ApiImplicitParam(name = "shopid", value = "书店ID",
            required = true, dataType = "long", paramType = "path",
            dataTypeClass = Long.class)
    @GetMapping(value = "/{shopid}")
    public AjaxResult getInfo(@PathVariable("shopid") Long shopid) {
        return AjaxResult.success(shopService.selectShopById(shopid));
    }
    @ApiOperation("新增书店(22001010613胡宇星)")
    @PostMapping
    public AjaxResult add(@RequestBody Shop shop) {
        return AjaxResult.success(shopService.insertShop(shop));
    }
    @ApiOperation("修改书店(22001010613胡宇星)")
    @PutMapping
    public AjaxResult edit(@RequestBody Shop shop) {
        return AjaxResult.success(shopService.updateShop(shop));
    }
    @ApiOperation("删除书店(22001010613胡宇星)")
    @ApiImplicitParam(name = "shopid", value = "书店ID", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
    @DeleteMapping("/{shopid}")
    public AjaxResult remove(@PathVariable Long shopid) {
        return AjaxResult.success(shopService.deleteShopById(shopid));
    }
}
